home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk16 / arrays / arrays (.txt) next >
AmigaBASIC Source Code  |  1995-03-18  |  2KB  |  102 lines

  1. ' This program will compute the amount of memory an array will
  2. ' require from the system. Just finish typing the array with your
  3. ' variable (remembering to add special characters which define the
  4. ' type ($, !, #, %) of the variable.
  5. '
  6. ' written by: William H. Bartell
  7. '
  8. ' This program may be freely distributed, but please
  9. ' include my name with all copies.
  10. '
  11.  
  12. start:
  13.   DIM dm&(255)
  14.   FOR i%= 0 TO 255
  15.     dm&(i%)=0
  16.   NEXT i%
  17.  
  18. newdim:
  19.   n%= 0
  20.   CLS
  21.   PRINT "Complete the DIMension statement below to compute"
  22.   PRINT "how much memory the array will require."
  23.   PRINT "Enter EXIT to quit.
  24.   LOCATE 6,5
  25.   LINE INPUT "DIM ";d$
  26.   IF UCASE$(LEFT$(d$,1))="E" AND INSTR(d$,"(")=0 THEN END
  27.   LSET d$= d$
  28.   z%= INSTR(d$," ")
  29.   WHILE z%
  30.     d$= LEFT$(d$,z%-1)+RIGHT$(d$,z%+1)
  31.     z%= INSTR(d$," ")
  32.   WEND
  33.   IF LEN(d$)=0 THEN GOTO badinput
  34.   p1%= INSTR(d$,"(")
  35.   IF p1%=0 OR p1%<2 OR p1%>41 THEN GOTO badinput
  36.   prec%= ASC(MID$(d$,p1%-1,1))
  37.   IF prec%=37 THEN
  38.         bytlen%= 2
  39.   ELSEIF prec%=33 OR prec%=38 OR prec%=46 OR (prec%>47 AND prec%<58) OR (prec%>64 AND prec%<91) OR (prec%>96 AND prec%<123) THEN
  40.         bytlen%= 4
  41.   ELSEIF prec%=36 THEN
  42.         bytlen%= 5
  43.   ELSEIF prec%=35 THEN
  44.         bytlen%= 8
  45.   ELSE 
  46.         GOTO badinput
  47.   END IF
  48.   p2%= INSTR(d$,")")
  49.   IF p2%=0 THEN GOTO badinput
  50.   p2%= INSTR(d$,",")
  51.   WHILE p2%
  52.     GOSUB addit
  53.     p2%= INSTR(p1%+1,d$,",")
  54.   WEND
  55.   p2%= INSTR(d$,")")
  56.   GOSUB addit
  57.   total&= 1
  58.   FOR i%= 1 TO n%
  59.     total&= total&*(dm&(i%)+1)
  60.   NEXT i%
  61.   total&= total&*bytlen%
  62.   total&= total&+12+2*(n%-1)
  63.   IF bytlen%=5 THEN 
  64.     total#= total&+0.5
  65.     total&= CLNG(total#)
  66.   END IF
  67.   LOCATE 8,1
  68.   PRINT "The total memory requirement for this"
  69.   PRINT "variable array is ";
  70.   IF bytlen%=5 THEN PRINT "at least ";
  71.   PRINT total&;" bytes."
  72.   IF bytlen%=5 THEN
  73.     PRINT "Add 1 byte for all characters which may"
  74.     PRINT "be used in the array during program execution."
  75.     PRINT "This will probably mean making a guess as to"
  76.     PRINT "how many characters there will be."
  77.   END IF
  78.   GOSUB hold
  79.   GOTO newdim
  80.   
  81. addit:
  82.   n%= n%+1
  83.   dm&(n%)= VAL(MID$(d$,p1%+1,p2%-p1%))
  84.   p1%= p2% 
  85.   RETURN
  86.  
  87. badinput:
  88.   LOCATE 8,1
  89.   PRINT CHR$(7);"Bad DIM statement, please try again."
  90.   GOSUB hold
  91.   GOTO newdim
  92.   
  93. hold:
  94.   PRINT
  95.   PRINT "Press ANY key to continue..."
  96.   z$= ""
  97.   WHILE z$=""
  98.     z$= INKEY$
  99.   WEND
  100.   RETURN
  101.  
  102.